package com.gg.fmallspringboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gg.fmallspringboot.entity.UserAddr;
import com.gg.fmallspringboot.mapper.UserAddrMapper;
import com.gg.fmallspringboot.model.Result;
import com.gg.fmallspringboot.service.UserAddrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserAddrServiceImpl implements UserAddrService {


    @Resource
    private UserAddrMapper userAddrMapper;

//    public UserAddrServiceImpl(UserAddrMapper userAddrMapper) {
//        this.userAddrMapper = userAddrMapper;
//    }


    @Override
    public Result<UserAddr> getAllById(Integer userId) {
        QueryWrapper<UserAddr> qw = new QueryWrapper();
        qw.eq("user_id",userId);
        List<UserAddr> userAddrList = userAddrMapper.selectList(qw);
        Result result;
        if (userAddrList==null){
            result = new Result(1,"查询失败");
        }else {
            result = new Result(0,"查询成功",userAddrList);
        }
        return result;
    }

    @Override
    public int addUserAddr(Integer userId) {
        return userAddrMapper.addUserAddr(userId);
    }

    @Override
    public int updateUserAddr(Integer addrId) {
        return userAddrMapper.updateUserAddr(addrId);
    }

    @Override
    public int deleteUserAddr(Integer addrId) {
        return userAddrMapper.deleteUserAddr(addrId);
    }
}
